/*
 * Holds Nurse, Doctor, Patient objects created
 * Has add/search/delete methods
 */
import java.io.Serializable;
import java.security.MessageDigest;
import java.util.ArrayList;

public class MemberData implements Serializable{
	private ArrayList <Member> members;
	
	public MemberData()
	{
		members = new <Member> ArrayList();
	}
	
	
	//manipulator methods
	public void addMember(Member m) {		//too redundant? or would the .add method not work out of this class?
		members.add(m);
	}
	
	
	//Returns a the member that matches the passed ID number
	public Member getMember(int id) {
		
		//checks all indeces for match
		for(int i = 0; i < members.size(); i++)
		{
			if(id == ((Member)members.get(i)).getID())
			{
				return (Member)members.get(i);
			}
		}
		// returns null if not found
		return null;
	}
	
public Member getMemberAtIndex(int i) {
		
		if(i >= 0 && i < members.size())
		{
			return members.get(i);
		}
		return null;
	}
	
	
	
	
	
	public Member getMember(String u) {
		//checks all indeces for match
		for(int i = 0; i < members.size(); i++)
		{
			if(u.equalsIgnoreCase(((Member)members.get(i)).getUserName()))
			{
				return (Member)members.get(i);
			}
		}
		// returns null if not found
		return null;
	}
	
	
	public void deleteMember(int id) {
		members.remove(getMember(id));
	}
	
	
	public int getSize()
	{
		return members.size();
	}
	
	
	public Member validate(String u, MessageDigest p)
	{
		Member temp = getMember(u);
		if(temp == null)
		{
			return null;
		}
		
		else
		{
			if(temp.checkPass(p))
			{
				return temp;
			}
		}
		return null;
		
	}
	//sorting
	
	/*
	public ArrayList sortList(String sortType) {
		ArrayList temp = members;
		
		switch(sortType.toLowerCase()) {	//sort using ListIterator?
			case "object type":		//groups nurses, doctors, and patients together
				
				return temp;
				
			case "id number":		//sorted by id in ascending order
				
				return temp;
				
			case "last name":		//sorted by last name alphabetically (do we need a first name one as well or is it whatever?)
				
				return temp;
				
			case "relationship":	//displays nurse1, nurse1's doctors, nurse1's doctor's patients etc
				
				return temp;
		}
		
	}
	*/
}
